package com.example.mrzhou.lvmm.view.fragment.home;


import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.view.View;

import com.example.mrzhou.lvmm.R;
import com.example.mrzhou.lvmm.commom.base.BaseFragment;
import com.example.mrzhou.lvmm.commom.utils.FragmentViewPagerUtils;
import com.example.mrzhou.lvmm.commom.view.BanViewPager;
import com.example.mrzhou.lvmm.entity.home.HomeTitle;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * A simple {@link Fragment} subclass.
 */
public class HomeFirstFragment extends BaseFragment {

    public static final String KEY_TITLE = "homeTitle";
    public static final String KEY_INDEX = "index";
    @BindView(R.id.tab_home_second)
    TabLayout tabHomeSecond;
    @BindView(R.id.bvp_home_second)
    BanViewPager bvpHomeSecond;
    private HomeTitle homeTitle;
    private int index;

    private List<String> list = new ArrayList<>();
    private List<Fragment> fragments = new ArrayList<>();

    public HomeFirstFragment() {
        // Required empty public constructor
    }

    public static HomeFirstFragment newInstance(HomeTitle homeTitle, int index) {

        Bundle args = new Bundle();
        args.putSerializable(KEY_TITLE, homeTitle);
        args.putInt(KEY_INDEX, index);
        HomeFirstFragment fragment = new HomeFirstFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected int getLayout() {
        return R.layout.fragment_home_first;
    }

    @Override
    protected void initView(View view) {
        ButterKnife.bind(this,view);
        homeTitle = (HomeTitle) getArguments().getSerializable(KEY_TITLE);
        index =getArguments().getInt(KEY_INDEX);
        initData();
    }

    @Override
    protected void initData() {
        list.clear();
        fragments.clear();
        List<HomeTitle.DatasBean.InfosBean> infos = homeTitle.getDatas().get(index).getInfos();
        for (int i = 0; i < infos.size(); i++) {
            list.add(infos.get(i).getTitle());
            fragments.add(HomeSecondFragment.newInstance(infos.get(i).getBackWord1(),infos.get(i).getBackWord2()));
        }
        FragmentViewPagerUtils utils = new FragmentViewPagerUtils();
        utils.fragmentVpUtils(fragments,list,bvpHomeSecond,tabHomeSecond,getChildFragmentManager());
    }

}
